package de.se2.sharebox.classes;

import java.util.Vector;

/**
 *
 * @author Gruppe 10
 *
 */
public class Folder extends SystemDataType
{
	private Vector<File> fileCollection;
	private Vector<Folder> folderCollection;

	public Folder(String name, UserAccount owner)
	{
		super(name, owner);
	}

	/**
	 * Konstruktor
	 *
	 * @param folderName -
	 *          Ordnername
	 * @param owner -
	 *          Besitzer
	 * @param fileCollection -
	 *          Dateicollection
	 * @param folderCollection -
	 *          Ordnercollection
	 */
	public Folder(String folderName, UserAccount owner, Vector<File> fileCollection, Vector<Folder> folderCollection)
	{
		super(folderName, owner);
		this.fileCollection = fileCollection;
		this.folderCollection = folderCollection;
	}

	public Vector<File> getFileCollection()
	{
		return fileCollection;
	}

	public boolean existFolderWithName(String folderName)
	{
		for (int i = 0 ; i < folderCollection.size() ; i++)
		{
			if (folderCollection.get(i).getName().equals(folderName))
				return true;
		}
		return false;
	}

	public Folder getFolderByName(String folderName)
	{
		for (int i = 0 ; i < folderCollection.size() ; i++)
		{
			if (folderCollection.get(i).getName().equals(folderName))
				return folderCollection.get(i);
		}
		return null;
	}

	public boolean existFileWithName(String fileName)
	{
		for (int i = 0 ; i < fileCollection.size() ; i++)
		{
			if (fileCollection.get(i).getName().equals(fileName))
				return true;
		}
		return false;
	}

	public File getFileByName(String fileName)
	{
		for (int i = 0 ; i < fileCollection.size() ; i++)
		{
			if (fileCollection.get(i).getName().equals(fileName))
				return fileCollection.get(i);
		}
		return null;
	}

	public Vector<Folder> getFolderCollection()
	{
		return folderCollection;
	}

	public boolean addFile(File file)
	{
		Log.getInstance().addEntry("Folder", "add file '" + file.getName() + "' to folder " + getName());
		return fileCollection.add(file);
	}

	public boolean addFolder(Folder folder)
	{
		Log.getInstance().addEntry("Folder", "add folder '" + folder.getName() + "' to folder " + getName());
		return folderCollection.add(folder);
	}

	public boolean removeFile(File file)
	{
		Log.getInstance().addEntry("Folder", "remove file '" + file.getName() + "' from folder " + getName());
		return fileCollection.remove(file);
	}

	public boolean removeFolder(Folder folder)
	{
		Log.getInstance().addEntry("Folder", "remove folder '" + folder.getName() + "' from folder " + getName());
		return folderCollection.remove(folder);
	}
}
